package com.wayin.lift.controller.check;

import java.util.Arrays;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wayin.lift.entity.MigrantsEntity;
import com.wayin.lift.service.MigrantsService;
import com.wayin.common.utils.*;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;

/**
 * 访客
 *
 * @author HYXK
 * @email null@qq.com
 * @date 2020-05-26 09:56:39
 */
@Api(tags = "访客接口")
@RestController
@RequestMapping("/migrants")
public class MigrantsController {

    @Autowired
    private MigrantsService migrantsService;

    /**
     * 列表
     */
    @ApiOperation("查找所有访客信息")
    @RequestMapping(value = "/list", method = GET)
    public R list(){
        List<MigrantsEntity> page = migrantsService.findAllMigrants();

        return R.ok().put("page", page);
    }

    /**
     * 查看当天访客
     */
    @ApiOperation("查看当天访客")
    @RequestMapping(value = "/findThisDay", method = GET)
    public R findThisDay(){
        List<MigrantsEntity> m = migrantsService.findThisDay();
        return R.ok().put("page", m);
    }


    /**
     * 信息
     */
    @ApiOperation("根据{mId}查找访客信息")
    @RequestMapping(value = "/info/{mId}", method = GET)
    public R info(@PathVariable("mId") Long mId){
		MigrantsEntity migrants = migrantsService.getById(mId);

        return R.ok().put("migrants", migrants);
    }

    /**
     * 保存
     */
    @ApiOperation("添加访客信息")
    @RequestMapping(value = "/save", method = POST)
    public R save(@RequestBody MigrantsEntity migrants){

        return migrantsService.save(migrants) ? R.ok() : R.error();
    }

    /**
     * 修改
     */
    @ApiOperation("修改访客信息")
    @RequestMapping(value = "/update", method = POST)
    public R update(@RequestBody MigrantsEntity migrants){

        return migrantsService.updateById(migrants) ? R.ok() : R.error();
    }

    /**
     * 删除
     */
    @ApiOperation("删除访客信息")
    @RequestMapping(value = "/delete", method = PUT)
    public R delete(@RequestParam Long[] mIds){

        return migrantsService.removeByIds(Arrays.asList(mIds)) ? R.ok() : R.error();
    }

}
